import wx from 'weixin-jsapi';
import { getWxConfig } from '@/api/common';

// wxApi 接口注入权限验证
export default async function wxApiReady(jsApiList: string[]): Promise<any> {
	const configRes = await getWxConfig();
	const { appId, timestamp, nonceStr, signature } = configRes.data;

	wx.config({ debug: false, appId, timestamp, nonceStr, signature, jsApiList });

	return new Promise<any>((resolve, reject) => {
		wx.ready((res: Response) => {
			resolve(res);
		});

		wx.error((err: Error) => {
			reject(err);
		});
	});
}
